package com.kaifamiao.springbootjwt.controller;

import com.kaifamiao.springbootjwt.config.JwtUtils;
import com.kaifamiao.springbootjwt.config.ResultT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;


@RestController
public class LoginController {
    // 注入jwt工具类
    @Autowired
    private JwtUtils jwtUtils;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResultT login(String name, String psw) {
        String userId = "132";
        String token = jwtUtils.generateToken(userId);
        return ResultT.ok().put("token", token);
    }

    @GetMapping({"/", "/login"})
    public ModelAndView login() {
        return new ModelAndView("login");
    }

    @GetMapping({"/index"})
    public ModelAndView index() {
        return new ModelAndView("index");
    }

    @GetMapping("/gateway")
    public ResultT check() {
        return ResultT.ok();
    }
}
